<template>
  <div class="body">
    <header class="header">
      <div class="title">
        <img src="../../../assets/images/01_11.png" alt="" class="img_zuo" @click="back" />
        <div>工作清单</div>
        <!-- <span @click="btn">测</span> -->
      </div>
    </header>
    <div class="contant">
      <div class="security">
        <div></div>
        <div class="yinhuan_box" v-for="(item, index) in patrolList" :key="index">
          <div class="yinhuan">
            <div class="yinhuan_img">
              <img :src="item.name === '巡查' ? Exclamations : Exclamation" />
              <div class="ellipsis-2">{{ item.name + '隐患' }}</div>
            </div>
            <img @click="jumpTrouble(item.id, item.isNo, item.name)" class="img_plus"
              :src="item.isNo === 1 ? img : imgs" />
          </div>
        </div>
      </div>
      <div class="button-box">
        <div class="button" @click="click">结束巡查</div>
      </div>
    </div>
    <div class="tanbox" v-show="show">
      <div class="conte">
        <div class="tishi">
          <div>提示</div>
          <img src="../../../assets/images/false.png" @click="show = false" />
        </div>
        <div class="tk-main">
          <div class="shangc">请上传附件</div>
          <div class="queding" @click="show = false">确定</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { Toast } from 'vant';
  export default {
    name: 'hard_work',
    data() {
      return {
        Exclamation: require('../../../assets/images/logo7.png'),
        Exclamations: require('../../../assets/images/workman.png'),
        img: require('../../../assets/images/plus.png'),
        imgs: require('../../../assets/images/gou.png'),
        show: false,
        patrolList: [],
        id: null
      };
    },
    components: {
      [Toast.name]: Toast
    },
    mounted() {
      var _this = this;
      this.id = Number(localStorage.getItem("jzw_inspect_detail_patrolTroubleshootId"))
      this.query();

      //物理返回
      // window.addEventListener("popstate", function(){
      //   _this.back();
      // }, false);
    },
    methods: {
      back() {
        this.$router.push("/detail_list");
      },
      btn() {
        this.$router.push("/yinhuanhard");
      },
      query() {
        const that = this;
        const params = {
          patrolId: that.id
        }
        that.axios.get(`${that.$global_msg.Url.host}/partroInspection/selectDangerIsNo`,
          { params }).then(res => {
            console.log(res)
            if (res.data.code === 200) {
              that.patrolList = res.data.rows;
            } else {
              Toast('获取数据失败！')
            }
          })
      },
      jumpTrouble(id, isNo, name) {
        this.$router.push({
          path: '/yinhuanhard',
          query: { id, isNo, name }
        });
      },
      click() {
        let that = this;
        let a = [];
        let b = [];
        that.patrolList.map(res => {
          if (res.name !== '巡查') {
            if (res.isNo !== 0) {
              a.push(res.isNo);
            }
          } else {
            if (res.isNo !== 0) {
              b.push(res.isNo);
            }
          }
        })
        if (a.length >= 1) {
          that.show = true;
        } else {
          if (that.patrolList.length === 1 && b.length > 0) {
            that.show = true;
          } else {
            that.finish();
          }
        }
      },
      finish() {
        let params = { patrolTroubleshoot: this.id }
        this.axios.get(`${this.$global_msg.Url.host}/partroInspection/finish`,
          { params }).then(res => {
            console.log(res)
            if (res.data.code === 200) {
              sessionStorage.setItem("jzw_community_list_shequ_id", res.data.rows)
              this.$router.push({ path: '/inspection' });
            } else {
              this.$toast(res.data.msg);
            }
          }).catch(error => {
            this.$terminal._error(error)
          });
      }
    }
  }
</script>

<style scoped>
  .ellipsis-2 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
  }

  .tk-main {
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 60px 0;
  }

  .shangc {
    width: 80%;
    margin-bottom: 40px;
  }

  .queding {
    width: 30%;
    color: white;
    text-align: center;
    background-color: #2B6CFE;
    border-radius: 0.092592rem;
    padding: 20px 0;
  }

  .tishi {
    border-bottom: 0.018518rem solid #f2f2f2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.2rem 0.5rem;
  }

  .tishi img {
    width: 0.4rem;
  }

  .conte {
    width: 70%;
    background: #FFFFFF;
    border-radius: 0.185185rem;
  }

  .tanbox {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .yinhuan_img {
    display: flex;
    align-items: center;
  }

  .yinhuan_img img {
    width: 0.7rem;
    height: 0.7rem;
    margin-right: 0.3rem;
  }

  .img_plus {
    width: 0.5rem;
  }

  .yinhuan_box {
    padding: 0 0.4rem;
    border-bottom: 1px solid #f2f2f2;
  }

  .yinhuan {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #F7F7F9;
    height: 1.3rem;
    align-items: center;
  }

  .security {
    margin-top: 0.2rem;
    background-color: #FFFFFF;
  }

  .button-box {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 50px;
    background-color: #fff;
    box-sizing: border-box;
  }

  .button {
    color: white;
    text-align: center;
    background-color: #2B6CFE;
    padding: 30px 0;
    border-radius: 0.105185rem;
  }

  .contant {
    margin: 1.8519rem 0;
    border: 1px solid white;
  }

  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }
</style>